/*
 * SoftwareSAR - 1.0
 */
package br.com.cpqd.ssar.gerenciador.gui;

import br.com.cpqd.ssar.gerenciador.GerenciamentoNucleo;
import br.com.cpqd.ssar.gerenciador.Render;
import br.com.cpqd.ssar.mediador.gui.*;
import java.awt.Color;
import java.util.Vector;
import javax.swing.JColorChooser;

/**
 * Janela de Atribuição de Material
 * @author  Rafael Buck
 * @version 1.0
 */
public class JanelaConfigurarGrid extends javax.swing.JDialog {

    /**
     * Controlador de Janelas
     */
    ControladorJanelas controladorJanelas;

    /**
     * Método Construtor
     * @param controladorJanelas ControladorJanelas
     * @param parent Frame
     * @param modal determina se a janela é modal ou não (impede o acesso as janelas abaixo)
     */
    public JanelaConfigurarGrid(GerenciamentoNucleo core, Vector listaRender, java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        btnLimpar.doClick();
        rFront = (Render) listaRender.get(0);
        rPers = (Render) listaRender.get(1);
        rTop = (Render) listaRender.get(2);
        rSide = (Render) listaRender.get(3);

        jPanelCor.setBackground(rTop.getCorGrid());
        //txtNumGrades.setText(String.valueOf(rTop.getTamGridX()));
        txtRotacao.setText(String.valueOf(core.getRotacao()));
        txtTranslacao.setText(String.valueOf(core.getTranslacao()));
        jChkVisivel.setSelected(rTop.isGridEnable());
        this.core = core;

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jSeparator1 = new javax.swing.JSeparator();
        btnConfirmar = new javax.swing.JButton();
        btnLimpar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        jChkVisivel = new javax.swing.JCheckBox();
        jLabel2 = new javax.swing.JLabel();
        jPanelCor = new javax.swing.JPanel();
        jButtonAlterarCor = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtRotacao = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtTranslacao = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Configurar Grade");
        setAlwaysOnTop(true);
        setLocationByPlatform(true);
        setModal(true);
        setResizable(false);

        jPanel1.setBackground(new java.awt.Color(231, 240, 250));

        btnConfirmar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/cpqd/ssar/gerenciador/gui/recursos/confirmar.png"))); // NOI18N
        btnConfirmar.setText("Confirmar");
        btnConfirmar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConfirmarActionPerformed(evt);
            }
        });

        btnLimpar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/cpqd/ssar/gerenciador/gui/recursos/limpar1.png"))); // NOI18N
        btnLimpar.setText("Limpar");
        btnLimpar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimparActionPerformed(evt);
            }
        });

        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/cpqd/ssar/gerenciador/gui/recursos/Cancelar.png"))); // NOI18N
        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        jChkVisivel.setBackground(new java.awt.Color(231, 240, 250));
        jChkVisivel.setText("Visível");

        jLabel2.setText("Cor:");

        jPanelCor.setBackground(new java.awt.Color(255, 255, 255));
        jPanelCor.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 102, 102)));
        jPanelCor.setToolTipText("Cor do Material");

        javax.swing.GroupLayout jPanelCorLayout = new javax.swing.GroupLayout(jPanelCor);
        jPanelCor.setLayout(jPanelCorLayout);
        jPanelCorLayout.setHorizontalGroup(
            jPanelCorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 39, Short.MAX_VALUE)
        );
        jPanelCorLayout.setVerticalGroup(
            jPanelCorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 19, Short.MAX_VALUE)
        );

        jButtonAlterarCor.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/cpqd/ssar/gerenciador/gui/recursos/color1.png"))); // NOI18N
        jButtonAlterarCor.setText("Cor");
        jButtonAlterarCor.setPreferredSize(new java.awt.Dimension(75, 23));
        jButtonAlterarCor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAlterarCorActionPerformed(evt);
            }
        });

        jLabel3.setText("Fator de Rotação:");

        jLabel4.setText("Grid:");

        jLabel6.setText("Fator de Translação:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addGap(18, 18, 18)
                                .addComponent(jPanelCor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(39, 39, 39)
                                .addComponent(jButtonAlterarCor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addGap(18, 18, 18)
                                .addComponent(jChkVisivel))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel3)
                        .addGap(18, 18, 18)
                        .addComponent(txtRotacao, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel6)
                        .addGap(18, 18, 18)
                        .addComponent(txtTranslacao, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 521, Short.MAX_VALUE)))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(209, Short.MAX_VALUE)
                .addComponent(btnConfirmar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnLimpar)
                .addGap(27, 27, 27)
                .addComponent(btnCancelar)
                .addGap(18, 18, 18))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(48, 48, 48)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jChkVisivel))
                        .addGap(39, 39, 39)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel2)
                            .addComponent(jPanelCor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jButtonAlterarCor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(62, 62, 62)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtRotacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(72, 72, 72)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel6)
                    .addComponent(txtTranslacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(40, 40, 40)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 45, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCancelar)
                    .addComponent(btnLimpar)
                    .addComponent(btnConfirmar))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void btnConfirmarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConfirmarActionPerformed
// TODO add your handling code here:
    if (txtTranslacao.getText().isEmpty()) {
        core.getInterfaceServicos().exibirMensagemAlerta("Campo \" Translação \" está vazio.");
        txtTranslacao.requestFocus();


    } else if (txtRotacao.getText().isEmpty()) {
        core.getInterfaceServicos().exibirMensagemAlerta("Campo \" Rotação \" está vazio.");
        txtRotacao.requestFocus();
    } else {

        rTop.setCorGrid(jPanelCor.getBackground());
        rTop.setDesenharGrid(jChkVisivel.isSelected());
//        rTop.setTamGridX(Integer.valueOf(txtNumGrades.getText()));

        rSide.setCorGrid(jPanelCor.getBackground());
        rSide.setDesenharGrid(jChkVisivel.isSelected());
//        rSide.setTamGridX(Integer.valueOf(txtNumGrades.getText()));

        rFront.setCorGrid(jPanelCor.getBackground());
        rFront.setDesenharGrid(jChkVisivel.isSelected());
//        rFront.setTamGridX(Integer.valueOf(txtNumGrades.getText()));

        rPers.setCorGrid(jPanelCor.getBackground());
        rPers.setDesenharGrid(jChkVisivel.isSelected());
//        rPers.setTamGridX(Integer.valueOf(txtNumGrades.getText()));
        core.setRotacao(Float.valueOf(txtRotacao.getText()));
        core.setTranslacao(Float.valueOf(txtTranslacao.getText()));

        dispose();
    }
}//GEN-LAST:event_btnConfirmarActionPerformed

private void btnLimparActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimparActionPerformed
// TODO add your handling code here:
    txtRotacao.setText("");
    txtTranslacao.setText("");
    jChkVisivel.setSelected(false);
    jPanelCor.setBackground(new Color(224, 223, 227));
}//GEN-LAST:event_btnLimparActionPerformed

private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
// TODO add your handling code here:
    dispose();
}//GEN-LAST:event_btnCancelarActionPerformed

private void jButtonAlterarCorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAlterarCorActionPerformed
// TODO add your handling code here:
    JColorChooser jColorChooser = new JColorChooser();
    jPanelCor.setBackground(JColorChooser.showDialog(null, "Escolher uma Cor", Color.BLACK));
}//GEN-LAST:event_jButtonAlterarCorActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnConfirmar;
    private javax.swing.JButton btnLimpar;
    private javax.swing.JButton jButtonAlterarCor;
    private javax.swing.JCheckBox jChkVisivel;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanelCor;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTextField txtRotacao;
    private javax.swing.JTextField txtTranslacao;
    // End of variables declaration//GEN-END:variables
    private GerenciamentoNucleo core;
    private ControladorJanelas janelas;
    Render rTop, rSide, rFront, rPers;
    public float rotacao;
    public float translacao;
}

